package com.example.zk1.register

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.blankj.utilcode.util.ToastUtils
import com.example.common.mvvm.BaseActivity
import com.example.zk1.R
import com.example.zk1.databinding.ActivityRegisterBinding

class RegisterActivity : BaseActivity<ActivityRegisterBinding,RegisterViewModel>() {
    override fun getLayout(): Int = R.layout.activity_register

    override fun getViewModel(): Class<RegisterViewModel>  = RegisterViewModel::class.java

    override fun initView() {
        binding.btnRegister.setOnClickListener {
            viewmodel.register(binding.etUsername.text.toString(),
            binding.etPassword.text.toString(),
            binding.etRepassword.text.toString())
        }

    }

    override fun initData() {
        viewmodel.success.observe(this){
            ToastUtils.showLong(it.message)
            if(it.code==200){
                setResult(102, Intent().putExtra("username",it.data.username).putExtra("password",it.data.password))
                finish()
            }
        }
        viewmodel.fail.observe(this){
            ToastUtils.showLong(it)
        }
    }

}